﻿using CID.Domain.Infrastructure;
using CID.Domain.Users;
using CID.Web.Models.Infrastructure;
using CID.Web.Support;
using CID.Web.Support.TemplateContentEdition;

namespace CID.Web.Controllers
{
    [CIDAuthorize(UserRole.Architect, UserRole.Manager)]
    public class TemplateTypeController : BaseCRUDController<ITemplateType, TemplateType, TemplateTypeViewModel>
    {
        protected override TemplateType CreateModel(TemplateTypeViewModel viewModel)
        {
            return new TemplateType(viewModel.Name, viewModel.Description, viewModel.TemplateContentEditorConverterType, viewModel.TemplateContentEditorViewName);
        }

        protected override void PrepareViewModelForView(TemplateTypeViewModel viewModel)
        {
            base.PrepareViewModelForView(viewModel);

            viewModel.AvailableTemplateContentEditorViewNames = TemplateContentEditorRegistry.Instance.GetAvailableTemplateContentEditorViewNames();
            viewModel.AvailableTemplateContentEditorConverterTypes = TemplateContentEditorRegistry.Instance.GetAvailableTemplateContentEditorConverterTypes();
        }
    }
}
